import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

/**
 * @Author Stringzhua
 * @Date 2024/9/26 19:28
 * description:
 */
public class lc49p1 {
    public List<List<String>> groupAnagrams(String[] strs) {
        HashMap<String, List<String>> map = new HashMap<>();
        for (String key : strs) {
            final char[] chars = key.toCharArray();
            Arrays.sort(chars);
            String sortKey = new String(chars);
            if (map.containsKey(sortKey)) {
                map.get(sortKey).add(key);
            } else {
                List<String> s = new ArrayList<>();
                s.add(key);
                map.put(sortKey, s);
            }
        }
        return new ArrayList<>(map.values());
    }
}
